void drawDogaLineRGB(int A[],int B[],int Rc,int Gc,int Bc,int Wc) {
  int ABxs,ABxf,ABys,AByf;
  int ABd=1;
  int ABi,ABj,ABk;
  // first lets make sure that ABxf>ABxs
  if (B[0]>A[0]) {ABxs=A[0];ABxf=B[0];ABys=A[1];AByf=B[1];}
  else {ABxs=B[0];ABxf=A[0];ABys=B[1];AByf=A[1];}
  if (AByf<ABys) ABd=-1;
  
  int ABdx=ABxf-ABxs;
  int ABdy=(AByf-ABys)*ABd;
  int ABdif=ABdy-ABdx;
    
  point(ABxs,ABys);
   
  if (ABdx>=ABdy) { // IF X-BASED
    ABi=ABxs;ABj=ABys;
    while (ABi!=ABxf) {
      if (ABdif>0) {ABi++;ABj+=ABd;ABdif+=ABdy-ABdx;}
      else {ABi++;ABdif+=ABdy;}
      stroke(Rc,Gc,Bc,Wc);
      point(ABi,ABj);
    }
  }
  else { // IF Y-BASED
    ABi=ABxs;ABj=ABys;
    while (ABj!=AByf) {
      if (ABdif>0) {ABi++;ABj+=ABd;ABdif+=ABdx-ABdy;}
      else {ABj+=ABd;ABdif+=ABdx;}
      stroke(Rc,Gc,Bc,Wc);
      point(ABi,ABj);
    }
  }
}

void drawDogaTriangleRGB(int A[],int B[],int C[],int Rc,int Gc,int Bc,int Wc) {
  //AB should be longer than CB so lets make it happen first.
  //...
  float AB[] = new float[] {B[0]-A[0],B[1]-A[1],0};
  float CB[] = new float[] {C[0]-B[0],C[1]-B[1],0};
  float ABL = DogaMakeUnitVector(AB);
  float CBL = DogaMakeUnitVector(CB);
  float temp=0;
  if (CBL>ABL) {//switch A with C, ABL with CBL, AB with CB
    temp = A[0]; A[0]=C[0]; C[0]=temp;
    temp = A[1]; A[1]=C[1]; C[1]=temp;
    temp = ABL; ABL=CBL; CBL=temp;
    temp = AB[0]; AB[0]=CB[0]; CB[0]=temp;
    temp = AB[1]; AB[1]=CB[1]; CB[1]=temp;
  }
  //When we go to the next pixel in AB we will check if we should also go to the next pixel in CB
  //1.find the pixel in A->B
  //2.find the pixel in C->B
  //3.draw a line between 1->2
  int CBxs,CBxf,CBys,CByf;
  int ABxs,ABxf,ABys,AByf;
  int CBd=1;
  int ABd=1;
  int CBi,CBj,CBk;
  int ABi,ABj,ABk;
  // first lets make sure that ABxf>ABxs
  if (B[0]>A[0]) {
    ABxs=A[0];ABxf=B[0];ABys=A[1];AByf=B[1];
    CBxs=C[0];CBxf=B[0];CBys=C[1];CByf=B[1];    
  }
  else {
    ABxs=B[0];ABxf=A[0];ABys=B[1];AByf=A[1];
    CBxs=B[0];CBxf=C[0];CBys=B[1];CByf=C[1];
  }
  if (AByf<ABys) ABd=-1;
  if (CByf<CBys) CBd=-1;
  
  int CBdx=CBxf-CBxs;
  int CBdy=(CByf-CBys)*CBd;
  int CBdif=CBdy-CBdx;
  int ABdx=ABxf-ABxs;
  int ABdy=(AByf-ABys)*ABd;
  int ABdif=ABdy-ABdx;
    
  //ABxs,ABys --> to CBxs,CBys
   
  if (ABdx>=ABdy) { // IF X-BASED
    ABi=ABxs;ABj=ABys;
    while (ABi!=ABxf) {
      if (ABdif>0) {ABi++;ABj+=ABd;ABdif+=ABdy-ABdx;}
      else {ABi++;ABdif+=ABdy;}
      stroke(Rc,Gc,Bc,Wc);
      point(ABi,ABj);
    }
  }
  else { // IF Y-BASED
    ABi=ABxs;ABj=ABys;
    while (ABj!=AByf) {
      if (ABdif>0) {ABi++;ABj+=ABd;ABdif+=ABdx-ABdy;}
      else {ABj+=ABd;ABdif+=ABdx;}
      stroke(Rc,Gc,Bc,Wc);
      point(ABi,ABj);
    }
  }
}

float absD(float x) {
  if (x>=0) return x;
  return -x;
}
